package com.hxkj.controller;

import com.github.pagehelper.PageInfo;
import com.hxkj.domain.po.LastestMessage;
import com.hxkj.domain.po.Message;
import com.hxkj.domain.vo.MessageVO;
import com.hxkj.service.MessageService;
import com.platform.common.domain.to.PageTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.Callable;

@RestController
@RequestMapping(value = "/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @RequestMapping(value = "/sendMessage")
    public void sendMessage(@ModelAttribute Message message, HttpServletRequest request) throws Exception{
        messageService.sendMessage(message, request);
    }

    @RequestMapping(value = "/getList")
    public Callable<PageInfo<LastestMessage>> getList(@ModelAttribute LastestMessage lastestMessage,
                                                      @ModelAttribute PageTo pageParams, HttpServletRequest request) throws Exception{
        return () -> messageService.selectMessageList(lastestMessage,pageParams,request);
    }

    @RequestMapping(value = "/getMessageChat")
    public Callable<PageInfo<MessageVO>> getMessageChat(@ModelAttribute Message message, @ModelAttribute PageTo pageParams,
                                                        HttpServletRequest request) throws Exception{
        return () -> messageService.getMessageChat(message,pageParams,request);
    }

    @RequestMapping(value = "/batchDeleteMessage")
    public void batchDeleteMessage(String ids, HttpServletRequest request) throws Exception{
        messageService.batchDeleteMessage(ids, request);
    }

    @RequestMapping(value = "/batchModifyMessageStatus")
    public void batchModifyMessageStatus(String ids, HttpServletRequest request) throws Exception{
        messageService.batchModifyMessageStatus(ids, request);
    }

    @RequestMapping(value = "/deleteMessage")
    public void deleteMessage(String messageId, HttpServletRequest request) throws Exception{
        messageService.deleteMessage(messageId, request);
    }
}
